package com.example.myapplicationchat;

import android.content.Intent;
import android.os.Bundle;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button publish_button=findViewById(R.id.publish_button);
        publish_button.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(MainActivity.this,share.class);
                startActivity(intent);
            }
        });

        // 获取 ScrollView 中的 LinearLayout
        RelativeLayout upperLayout = findViewById(R.id.upperLayout);


        // 获取下部分 ImageView1世界
        ImageView imageView1 = findViewById(R.id.imageView1);
        imageView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 加载世界页面布局
                View myView = LayoutInflater.from(MainActivity.this).inflate(R.layout.world, null);

                // 移除 ScrollView 中的所有子视图
                upperLayout.removeAllViews();

                // 将世界页面布局添加到 ScrollView 中
                upperLayout.addView(myView);
                Button publish_button=findViewById(R.id.publish_button);
                publish_button.setOnClickListener(new View.OnClickListener(){
                    @Override
                    public void onClick(View view) {
                        Intent intent=new Intent(MainActivity.this,share.class);
                        startActivity(intent);
                    }
                });
            }
        });

        // 获取下部分 ImageView2好友动态
        ImageView imageView2 = findViewById(R.id.imageView2);
        imageView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                View myView = LayoutInflater.from(MainActivity.this).inflate(R.layout.friend, null);
                upperLayout.removeAllViews();
                upperLayout.addView(myView);
                Button publish_button=findViewById(R.id.publish_button);
                publish_button.setOnClickListener(new View.OnClickListener(){
                    @Override
                    public void onClick(View view) {
                        Intent intent=new Intent(MainActivity.this,share.class);
                        startActivity(intent);
                    }
                });
            }
        });

        // 获取下部分 ImageView3消息
        ImageView imageView3 = findViewById(R.id.imageView3);
        imageView3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                View myView = LayoutInflater.from(MainActivity.this).inflate(R.layout.message, null);
                upperLayout.removeAllViews();
                upperLayout.addView(myView);
            }
        });

        // 获取下部分 ImageView4我的
        ImageView imageView4 = findViewById(R.id.imageView4);
        imageView4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                View myView = LayoutInflater.from(MainActivity.this).inflate(R.layout.my, null);
                upperLayout.removeAllViews();
                upperLayout.addView(myView);

                TextView username=findViewById(R.id.nickname_text_view);
                username.setOnClickListener(new View.OnClickListener(){
                    @Override
                    public void onClick(View view) {
                        Intent intent=new Intent(MainActivity.this,username.class);
                        startActivity(intent);
                    }
                });

                TextView password=findViewById(R.id.signature_text_view);
                password.setOnClickListener(new View.OnClickListener(){
                    @Override
                    public void onClick(View view) {
                        Intent intent=new Intent(MainActivity.this,password.class);
                        startActivity(intent);
                    }
                });
            }
        });
    }
}
